#!/usr/bin/env python

import pexpect
import sys

child = pexpect.spawn('rman target /')
child.timeout=3000
fout = file('/home/oracle/fastarea/mylog_0.txt','a')
child.logfile = fout
#child.logfile = sys.stdout
f1=open('/home/oracle/fastarea/e.log','a+')
child.expect("RMAN>")
try:
#    child.sendline("backup database plus archivelog format '/home/oracle/fastre/fullback-%T-%U.bak';")
    child.sendline("backup incremental level 0 database;")
except Exception,e:
    print str(e)
    f1.write(e)
child.expect("RMAN>")
try:
    child.sendline("delete obsolete;")
    child.expect("YES or NO")
    child.sendline("YES")
except Exception,e:
    print str(e)
    f1.write(e)
f1.close()
child.expect("RMAN>")

child.sendline('exit')
child.close()

